package gw.com.android.ui.positions;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.gwtsz.android.rxbus.RxBus;
import com.gwtsz.gts2.hx.R;

import gw.com.android.app.AppMain;
import gw.com.android.model.ConfigType;
import gw.com.jni.library.terminal.GTSConst;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import www.com.library.app.Logger;
import www.com.library.view.RecycleViewDivider;

/**
 * 当日盈亏界面
 */
public class ProfitFragment extends SubFragment {

    public ProfitFragment() {
        // Required empty public constructor
    }

    public static ProfitFragment newInstance() {
        ProfitFragment fragment = new ProfitFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {

        }
    }

    @Override
    protected void initViewData() {
        mCurrentTag = ConfigType.TAB_PROFIT_TYPE;
        mAdapter = new ProfitAdapter(getActivity(), mListView);
        mListView.addItemDecoration(new RecycleViewDivider(getActivity(), LinearLayoutManager.VERTICAL));
        mListView.setAdapter(mAdapter);
        mListView.setVisibility(View.VISIBLE);
    }

    @Override
    public void registerRxBus() {
        super.registerRxBus();
        Disposable closeListRegister = RxBus.getInstance().registertoObservableSticky(GTSConst.REPLY_WIN_LIST + "", Bundle.class).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Bundle>() {

                    @Override
                    public void accept(@NonNull Bundle bundle) throws Exception {
                        Logger.i("当日盈亏列表刷新MainActivity 当日盈亏列表回包接收到回调");
                        refreshViewData();
                    }
                });
        bindSubscription(closeListRegister);
    }

    @Override
    public void setEmptyView() {
        mEmptyView.setText(AppMain.getAppString(R.string.order_profit_no_date));
        mCreateOrder.setVisibility(View.GONE);
    }

}
